function getjsonfromurl(xmlhttp, url) {
    var json;
    xmlhttp.open("POST", url, false); //false para que sea sincrono

    var t = navigator.userAgent;
    var t2 = t.indexOf("F");
    if (t2 > -1) {
        t2 = t.substring(t2, t.length);
        t2 = t2.replace("Firefox/", "");
    }
    else
        t2 = "";


    if (t2.indexOf("3") > -1) {
        xmlhttp.onload = xmlhttp.onerror = xmlhttp.onabort = function () {
            var m_res = xmlhttp.responseText;
            try {
                json = eval(m_res);
            } catch (e) {
                try {
                    json = JSON.parse(m_res);
                } catch (e2) {
                    json = "[E]" + m_res;
                }
            }
        };

    } else {
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var m_res = xmlhttp.responseText;
                    try {
                        json = eval(m_res);
                    } catch (e) {
                        try {
                            json = JSON.parse(m_res);
                        } catch (e2) {
                            json = "[E]" + m_res;
                        }
                    }
                }
            }
        }
    }
    xmlhttp.send(null);
    return json;
}

function getXMLObject() {
    var xmlHttp = false;
    try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
        try {
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
            } catch (e) {
                xmlHttp = false;
            }
        }
    }
    return xmlHttp;
}

function gettextfromurl(xmlhttp, url) {
    var html;
    xmlhttp.open("POST", url, false); //false para que sea sincrono
    var t = navigator.userAgent;
    var t2 = t.indexOf("F");
    if (t2 > -1) {
        t2 = t.substring(t2, t.length);
        t2 = t2.replace("Firefox/", "");
    }
    else
        t2 = "";
    if (t2.indexOf("3") > -1) {
        xmlhttp.onload = xmlhttp.onerror = xmlhttp.onabort = function () {
            html = xmlhttp.responseText;
        };
    } else {
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    html = xmlhttp.responseText;
                }
            }
        }
    }
    xmlhttp.send(null);
    return html;
}

function gettextfromurl_asinc(xmlhttp, url) {
    var html;
    xmlhttp.open("POST", url, true); //false para que sea sincrono
    var t = navigator.userAgent;
    var t2 = t.indexOf("F");
    if (t2 > -1) {
        t2 = t.substring(t2, t.length);
        t2 = t2.replace("Firefox/", "");
    }
    else
        t2 = "";
    if (t2.indexOf("3") > -1) {
        xmlhttp.onload = xmlhttp.onerror = xmlhttp.onabort = function () {
            html = xmlhttp.responseText;
        };
    } else {
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    html = xmlhttp.responseText;
                }
            }
        }
    }
    xmlhttp.send(null);
    return html;
}

function checkImg(url, marker) {
    var img = new Image();
    var estado = null;

    img.onload = function () {
        console.log("si existe");
        estado = true;

        marker.setIcon("../img/gps/markers/" + ti_puncol + "_" + size_marker + ".png");
    };

    img.onerror = function () {
        console.log("no existe: " + ti_puncol + "_" + size_marker + ".png");
        estado = false;

        var res = gettextfromurl(new getXMLObject(), "../wgp?xact=4&size=" + size_marker + "&color=" + ti_puncol);
        if (res == "ok") {
            console.log("respondio bien");
            marker.setIcon("../img/gps/markers/" + ti_puncol + "_" + size_marker + ".png");
        } else {
            console.log("se fue al carajo");
            marker.setIcon("http://chart.apis.google.com/chart?chst=d_map_spin&chld=" + size_marker + "|0|" + ti_puncol + "|8|_|");
        }
    };
    img.src = url;
    return estado
}

function mzoon_changed() {
    //console.log("-->"+map.getZoom());
    switch (map.getZoom()) {
        case 0:
        {
            g_markers_change_size('0.05');
            size_marker = '0.05';
            break;
        }
        case 1:
        {
            g_markers_change_size('0.10');
            size_marker = '0.10';
            break;
        }
        case 2:
        {
            g_markers_change_size('0.12');
            size_marker = '0.12';
            break;
        }
        case 3:
        {
            g_markers_change_size('0.13');
            size_marker = '0.13';
            break;
        }
        case 4:
        {
            g_markers_change_size('0.14');
            size_marker = '0.14';
            break;
        }
        case 5:
        {
            g_markers_change_size('0.15');
            size_marker = '0.15';
            break;
        }
        case 6:
        {
            g_markers_change_size('0.16');
            size_marker = '0.16';
            break;
        }
        case 7:
        {
            g_markers_change_size('0.17');
            size_marker = '0.17';
            break;
        }
        case 8:
        {
            g_markers_change_size('0.18');
            size_marker = '0.18';
            break;
        }
        case 9:
        {
            g_markers_change_size('0.19');
            size_marker = '0.19';
            break;
        }
        case 10:
        {
            g_markers_change_size('0.20');
            size_marker = '0.20';
            break;
        }
        case 11:
        {
            g_markers_change_size('0.25');
            size_marker = '0.25';
            break;
        }
        case 12:
        {
            g_markers_change_size('0.30');
            size_marker = '0.30';
            break;
        }
        case 13:
        {
            g_markers_change_size('0.40');
            size_marker = '0.40';
            break;
        }
        case 14:
        {
            g_markers_change_size('0.42');
            size_marker = '0.42';
            break;
        }
        case 15:
        {
            g_markers_change_size('0.44');
            size_marker = '0.44';
            break;
        }
        case 16:
        {
            g_markers_change_size('0.46');
            size_marker = '0.46';
            break;
        }
        case 17:
        {
            g_markers_change_size('0.48');
            size_marker = '0.48';
            break;
        }
        case 18:
        {
            g_markers_change_size('0.50');
            size_marker = '0.50';
            break;
        }
        case 19:
        {
            g_markers_change_size('0.52');
            size_marker = '0.52';
            break;
        }
        case 20:
        {
            g_markers_change_size('0.54');
            size_marker = '0.54';
            break;
        }
        case 21:
        {
            g_markers_change_size('0.56');
            size_marker = '0.56';
            break;
        }
    }
}

